package com.ywj.ehcache;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;

import net.sf.ehcache.search.attribute.AttributeType;

/**
 * 
 * @author yweijian
 * @date 2018年7月4日
 * @version 1.0
 */
@RestController
@RequestMapping("/")
public class TestController {
	
	/**
	 * http://127.0.0.1:8080/search
	 * 为了提高可视化测试，通过浏览器插件展示JSON数据
	 * @return
	 */
	@RequestMapping("search")
	public String search(){
		String cql = "";
		//select [cacheKey] from [cacheName] [condition] [order] 
		//cql = "select * from com.ywj.cache.document where title like '*土地征收*' order by pubdoctime desc";
		//cql = "select * from com.ywj.cache.document where depname like '*福州*' and istimeout='14'";
		//cql = "select * from com.ywj.cache.document where depname like '*福州*' and istimeout > '20'";
		//cql = "select * from com.ywj.cache.document where depname like '*福州*' and istimeout >= '15' and istimeout <= '20'";
		//cql = "select * from com.ywj.cache.document where depname like '*福州*' and adddate > '2018-4-01'";
		//cql = "select * from com.ywj.cache.document where depname like '*福州*' and istimeout between '15' and '20'";
		//cql = "select * from com.ywj.cache.document where id in('4922959','4917471','4892643')";
		//cql = "select * from com.ywj.cache.document where istimeout in('14','15','16')";
		cql = "select * from com.ywj.cache.document where depname != 福州市仓山区 "
				//+ "and title like '*土地征收*' "
				+ "and title like ? "
				//+ "and pubdoctime between '2018-04-01' and '2018-04-30' "
				+ "and istimeout between 10 and 20 "
				//+ "and istimeout in(14,15,16) "
				//+ "and istimeout <  20   "
				+ "and istimeout =  10   "
				+ "order by pubdoctime desc,istimeout asc";
		List<AttributeType> types = new ArrayList<AttributeType>();
		types.add(AttributeType.STRING);
		types.add(AttributeType.STRING);
		//types.add(AttributeType.DATE);
		//types.add(AttributeType.INT);
		types.add(AttributeType.INT);
		types.add(AttributeType.INT);
		List<Map<String, Object>> datas = EhcacheManager.search(cql, types);
		
		cql = "select * from com.ywj.cache.document where depname != ? "
				//+ "and title like '*土地征收*' "
				+ "and title like ? "
				+ "and pubdoctime between ? and ? "
				+ "and istimeout between ? and ? "
				//+ "and istimeout in(14,15,16) "
				//+ "and istimeout <  20   "
				+ "and istimeout =  ?   "
				+ "order by pubdoctime desc,istimeout asc";
		Object[][] paras = {
			{AttributeType.STRING,"福州市仓山区"},
			{AttributeType.STRING,"*琅岐海峡*"},
			{AttributeType.DATE,"2018-04-01,2018-04-30"},
			{AttributeType.INT,"10,20"},
			{AttributeType.INT,15}
		};
		datas = EhcacheManager.search(cql, paras);
		return JSON.toJSONString(datas);
	}
	
}
